﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using Microsoft.Win32;


namespace PSE.Updater.Monitor
{
    [RunInstaller(true)]
    public partial class ProjectInstaller : Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
        }

        protected override void OnAfterInstall(IDictionary savedState)
        {
            string key = string.Format(@"SYSTEM\CurrentControlSet\Services\{0}", this.serviceInstaller1.ServiceName);
            RegistryKey ckey = Registry.LocalMachine.OpenSubKey(key, true);
            // Good to always do error checking!

            if (ckey != null)
            {
                // Ok now lets make sure the "Type" value is there, 

                //and then do our bitwise operation on it.

                if (ckey.GetValue("Type") != null)
                {
                    ckey.SetValue("Type", ((int)ckey.GetValue("Type") | 256));
                }
                else
                    throw new Exception("Cannot find registry value Type");
            }
            else
                throw new Exception(string.Format("Cannot find registry key '{0}'", key));

            base.OnAfterInstall(savedState);
        }
    }
}
